#define DEBUG
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

const int maxn=30, inf=0x7ffffff;

int min(int a, int b) {
  return a<b ? a : b;
}

int solve(int o, int n, int s[]) {
  int ret=inf;
  if (o<n) {
    for (int i=1; i<=n; i++) {
      if (s[i]>=0) {
	for (int j=i+1; j<=n; j++) {
	  if (s[j]>=0) {
	    int x=s[i], y=s[j];
	    s[j] = -1;
	    s[i] = x+y;
	    ret = min(solve(o+1, n, s), ret);
	    if (!ret) {
	      return 0;
	    }
	    s[i] = x*y;
	    ret = min(solve(o+1, n, s), ret);
	    if (!ret) {
	      return 0;
	    }
	    s[i] = abs(x-y);
	    ret = min(solve(o+1, n, s), ret);
	    if (!ret) {
	      return 0;
	    }
	    s[i] = x, s[j]=y;
	  }
	}
      }
    }
  } else {
    for (int i=1; i<=n; i++) {
      if (s[i]>=0) {
	ret = s[i];
	break;
      }
    }
  }
  return ret;
}

int main() {
  static int s[maxn+1];
  int ans=0;
  for (int i=0; i<(1<<30); i++) {
    s[0] = 0;
    for (int j=0; j<30; j++) {
      if ((i>>j)&1) {
	s[++s[0]] = j+1;
      }
    }
    if (solve(1, s[0], s)) {
      ans = max(ans, s[0]);
    }
  }

  printf("%d", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
